package cn.rxls.community.controller;


import cn.rxls.community.dto.contractual.AddContractualDTO;
import cn.rxls.community.dto.contractual.ContractAssetConfirmDTO;
import cn.rxls.community.dto.contractual.ContractConfirmDTO;
import cn.rxls.community.dto.contractual.PageContractualByStateDTO;
import cn.rxls.community.result.Result;
import cn.rxls.community.vo.ContractualVO;
import cn.rxls.community.service.ContractualService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import javax.validation.constraints.Min;
import javax.validation.constraints.NotNull;
import java.util.List;

/**
 * 房屋合同(Contractual)表
 */
@RestController
@RequestMapping("contractual")
@Validated
public class ContractualController {
    /**
     * 服务对象
     */
    @Resource
    private ContractualService contractualService;


    /**
     * 新增合同
     *
     * @param contractual 实体对象
     * @return 新增结果
     */
    @PostMapping("/add")
    public Result<Boolean> insert(@RequestBody AddContractualDTO contractual) {
        return Result.success(contractualService.addContracting(contractual));
    }

    /**
     * 根据id查询合同内容
     *
     * @param id 合同id
     * @return 合同详情
     */
    @GetMapping("/detail")
    public Result<ContractualVO> selectDetailById(@Valid
                                                  @NotNull(message = "非法合同编号")
                                                  @Min(value = 1, message = "非法合同编号")
                                                  @RequestParam(value = "id", required = false) Long id) {
        return Result.success(contractualService.selectDetailById(id));
    }

    /**
     * 根据状态分页查询合同
     *
     * @param dto 实体对象
     * @return 新增结果
     */
    @GetMapping("/page/state")
    public Result<List<ContractualVO>> selectPageByState(@Valid @ModelAttribute PageContractualByStateDTO dto) {
        return Result.success(contractualService.selectPageByState(dto));
    }


    /**
     * 合同最终确认
     *
     * @param id 参数对象
     * @return 是否成功
     */
    @GetMapping("/final/confirm")
    public Result<Boolean> contractFinalConfirm(@Valid @NotNull(message = "非法合同") @RequestParam(value = "id", required = false) Long id) {
        return Result.success(contractualService.contractFinalConfirm(id));
    }

    /**
     * 合同资产确认
     *
     * @param dto 参数对象
     * @return 是否成功
     */
    @PostMapping("/asset/confirm")
    public Result<Boolean> contractAssetConfirm(@Valid @RequestBody ContractAssetConfirmDTO dto) {
        return Result.success(contractualService.contractAssetConfirm(dto));
    }


    /**
     * 合同重要内容确认
     *
     * @param id 合同编号
     * @return 是否成功
     */
    @GetMapping("/important/confirm")
    public Result<Boolean> contractImportantConfirm(@Valid @NotNull(message = "非法合同") @RequestParam(value = "id", required = false) Long id) {
        return Result.success(contractualService.contractImportantConfirm(id));
    }

}

